<?php
class Poll_Model_Option extends Engine_Db_Table_Row {
    public function getIdentity() {return $this->poll_option_id;}
    public function getTitle() {return $this->poll_option;} 
    
    public function getVotes($limit = NULL, $viewer = NULL) {
        $tb = Engine_Api::_()->getDbTable('Votes', 'Poll');
        $sl = $tb->select()->from(array('v' => $tb->info('name')))->where('option_id = ?', $this->getIdentity());        
        if ($viewer) $sl->columns("IF(user_id = '{$viewer->getIdentity()}', 1, 0) AS mark")->order('mark DESC');
        if ($limit) $sl->limit($limit);
        return $tb->fetchAll($sl);
    }
}


